package com.eedi.framework.logger.dal.mapper;

import com.eedi.framework.common.pojo.PageResult;
import com.eedi.framework.logger.controller.sys.vo.loginlog.SysLoginLogPageReq;
import com.eedi.framework.mybatis.core.mapper.BaseMapperX;
import com.eedi.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.eedi.framework.logger.dal.dataobject.SysLogLoginDO;
import com.eedi.framework.logger.enmus.SysLoginResultEnum;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface SysLoginLogMapper extends BaseMapperX<SysLogLoginDO> {

    default PageResult<SysLogLoginDO> selectPage(SysLoginLogPageReq reqVO) {
        LambdaQueryWrapperX<SysLogLoginDO> query = new LambdaQueryWrapperX<SysLogLoginDO>()
                .likeIfPresent(SysLogLoginDO::getUserIp, reqVO.getUserIp())
                .likeIfPresent(SysLogLoginDO::getLoginId, reqVO.getLoginId())
                .betweenIfPresent(SysLogLoginDO::getCreateTime, reqVO.getCreateTime());
        if (Boolean.TRUE.equals(reqVO.getStatus())) {
            query.eq(SysLogLoginDO::getLoginResult, SysLoginResultEnum.SUCCESS.getCode());
        } else if (Boolean.FALSE.equals(reqVO.getStatus())) {
            query.gt(SysLogLoginDO::getLoginResult, SysLoginResultEnum.SUCCESS.getCode());
        }
        // 降序
        query.orderByDesc(SysLogLoginDO::getId);
        return selectPage(reqVO, query);
    }

}
